Zooming and panning
Zooming and panning change the visible range of the axes: the user zooms with the mouse wheel or a pinch, and pans
by dragging the chart. Both features only move the MinLimit and MaxLimit of the axes, so the same range can also
be set from code, to show the data page by page or to drive the chart from a scroll bar. For axis limits in general,
see the axes article.
This article highlights the most used features. Every option is listed in the API explorer: ZoomAndPanMode, Axis and CartesianChartEngine.
Enable zooming
Zooming and panning are disabled by default. Set the ZoomMode property of the chart to enable them. With X, the
user zooms and pans only the X axis, and the Y axis fits the points that are visible in the current X range.
<CartesianChart
Series="series"
ZoomMode="LiveChartsCore.Measure.ZoomAndPanMode.X"> <!-- mark -->
</CartesianChart>

@page "/Lines/Zoom"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore
@using LiveChartsCore.SkiaSharpView
<CartesianChart
Series="@series"
ZoomMode="LiveChartsCore.Measure.ZoomAndPanMode.X">
</CartesianChart>
@code {
private ISeries[] series;
protected override void OnInitialized()
{
var values = Fetch();
series = new ISeries[]
{
new LineSeries<int>
{
Values = values
}
};
}
private static int[] Fetch()
{
var values = new int[100];
var r = new Random();
var t = 0;
for (var i = 0; i < 100; i++)
{
t += r.Next(-90, 100);
values[i] = t;
}
return values;
}
}
To change the default of every chart in the application, call
LiveCharts.Configure(config => config.WithZoomMode(ZoomAndPanMode.X)) when the application starts, before any chart
is created.
Zoom modes
ZoomMode is a ZoomAndPanMode flag
enum, so the options can be combined:
None: zooming and panning are disabled, the default.PanXandPanY: the user can pan the X or the Y axis.ZoomXandZoomY: the user can zoom the X or the Y axis, with the wheel, a pinch or a section.X: zoom and pan on the X axis, the same asPanX | ZoomX.Y: zoom and pan on the Y axis, the same asPanY | ZoomY.Both: zoom and pan on both axes, the same asX | Y.NoFit: lets the user move past the data, see fit to data.NoZoomBySection: disables the zoom by section.InvertPanningPointerTrigger: swaps the triggers of panning and zoom by section, see mouse and touch.
The last three flags only change the behaviour of the zoom and pan flags they are combined with.
Each gesture has its own flag, so they can be mixed: ZoomAndPanMode.ZoomX | ZoomAndPanMode.PanY zooms the X axis and
pans the Y axis, and ZoomAndPanMode.ZoomX zooms the X axis with no panning at all. Panning closes the tooltip while
the pointer drags, so a zoom-only mode keeps tooltips working when the user drags a finger over the chart on a touch
screen.
myChart.ZoomMode = ZoomAndPanMode.Both | ZoomAndPanMode.NoFit; // mark
With Y the user moves only the Y axis, and the X axis fits the points visible in the current Y range. With Both
the user moves both axes; it is easy to get lost in the data, so consider a button that
clears the zoom.

Mouse and touch
| Action | Mouse | Touch |
|---|---|---|
| Zoom | Mouse wheel | Pinch |
| Pan | Press the left button and drag | Press and drag |
| Zoom by section | Press the right button and drag | Double tap, keep the finger down on the second tap, drag |
The wheel zooms around the pointer: the value under the pointer stays in place.
This control does not handle the pinch gesture, use the mouse wheel to zoom.
When ZoomMode has the InvertPanningPointerTrigger flag, the triggers swap: the right button (or a double tap) pans,
and the left button (or a single tap) starts a zoom by section.
Zoom by section
The user can draw a rectangle over the chart and zoom to it. The feature is enabled with zooming, add the
NoZoomBySection flag to disable it. The section must start inside the plot area, and a drag shorter than 15 pixels
is ignored. When only one axis zooms, the rectangle covers the full height (or width) of the plot area, and only that
axis changes. The rectangle is drawn with a semi-transparent blue fill.

Zooming speed
ZoomingSpeed sets how much each step of the mouse wheel zooms, from 0 (slowest) to 1 (fastest). It is not the
speed of the animations. Each step in makes the visible range 1 - ZoomingSpeed times its length, each step out
divides the length by the same amount. The default is 0.2, so each step in shows 80% of the previous range. Values
under 0.1 work as 0.1 and values over 0.95 work as 0.95. The pinch gesture does not use this property.
<CartesianChart
Series="series"
ZoomMode="LiveChartsCore.Measure.ZoomAndPanMode.X"
ZoomingSpeed="0.1"> <!-- mark -->
</CartesianChart>
LiveCharts.Configure(config => config.WithZoomSpeed(0.1)) changes the default for every chart.
Fit to data
By default the chart keeps the data in view:
- Zooming out stops at the bounds of the data.
- Panning can go past the first or last point by the axis
BouncingDistance, a fraction of the plot area width (X axes) or height (Y axes). The default is0.25, a quarter of the plot area. When the pointer is released, the axis goes back to the data. SetBouncingDistanceto0to stop panning at the data.
Add the NoFit flag to let the user zoom and pan freely, past the data:

Minimum zoom
The axis MinZoomDelta property limits how deep the user can zoom: it is the smallest visible range the zoom can
reach, in data units (MaxLimit - MinLimit). Zooming in stops there, with the wheel, a pinch or a section. When it is
null, the default, the chart uses three times the smallest distance between two consecutive points of the data.
XAxes = new[]
{
new Axis
{
MinZoomDelta = 5 // the visible range is never shorter than 5 units // mark
}
};
Clearing the zoom
Set MinLimit and MaxLimit back to null (or double.NaN) to clear the zoom and fit the data to the chart again:
// where myChart is a reference to the chart in the UI
foreach (var x in myChart.XAxes)
{
x.MinLimit = null;
x.MaxLimit = null;
}
foreach (var y in myChart.YAxes)
{
y.MinLimit = null;
y.MaxLimit = null;
}
Reading the visible range
While the user zooms or pans, the chart sets the MinLimit and MaxLimit of the axes. The Axis class implements
INotifyPropertyChanged, so the PropertyChanged event tells when the visible range changes, by the user or by code:
// where myChart is a reference to the chart in the UI
myChart.XAxes.First().PropertyChanged += OnAxisPropertyChanged;
// ...
private void OnAxisPropertyChanged(object? sender, PropertyChangedEventArgs e)
{
if (e.PropertyName is not (nameof(Axis.MinLimit) or nameof(Axis.MaxLimit))) return;
var axis = (ICartesianAxis)sender!;
Trace.WriteLine($"{axis.Orientation} visible range: {axis.MinLimit} - {axis.MaxLimit}");
}
Paging
To show the data a page at a time, set MinLimit and MaxLimit from code. In this sample, the buttons move the X
axis by pages of eleven columns, and "Clear" shows all the data again. Each column is centered on its index, so
-0.5 to 10.5 shows the columns 0 to 10 completely. ZoomMode is X, so the user can still zoom and pan from
any page.

@page "/Axes/Paging"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.Measure;
<div>
<button type="button" class="btn btn-primary" @onclick="() => GoToPage(0)">Page 1</button>
<button type="button" class="btn btn-primary" @onclick="() => GoToPage(1)">Page 2</button>
<button type="button" class="btn btn-primary" @onclick="() => GoToPage(2)">Page 3</button>
<button type="button" class="btn btn-primary" @onclick="SeeAll">Clear</button>
</div>
<CartesianChart
Series="@series"
XAxes="@xAxes"
ZoomMode="LiveChartsCore.Measure.ZoomAndPanMode.X">
</CartesianChart>
@code {
private int[] values;
private ISeries[] series;
private Axis xAxis;
private Axis[] xAxes;
// for simplicity we use the page constructor
public View()
{
values = Fetch();
xAxis = new Axis();
series = new ISeries[]
{
new ColumnSeries<int> { Values = values }
};
xAxes = new[] { xAxis };
}
private void GoToPage(int page)
{
if (page == 0) { xAxis.MinLimit = -0.5; xAxis.MaxLimit = 10.5; }
else if (page == 1) { xAxis.MinLimit = 9.5; xAxis.MaxLimit = 20.5; }
else if (page == 2) { xAxis.MinLimit = 19.5; xAxis.MaxLimit = 30.5; }
}
private void SeeAll()
{
xAxis.MinLimit = null;
xAxis.MaxLimit = null;
}
private static int[] Fetch()
{
var random = new Random();
var trend = 100;
var values = new System.Collections.Generic.List<int>();
for (var i = 0; i < 100; i++)
{
trend += random.Next(-30, 50);
values.Add(trend);
}
return values.ToArray();
}
}
Scrollable chart
A second, smaller chart can work as a scroll bar. In this sample the main chart has ZoomMode set to X. Below it,
a chart 100 pixels tall plots the same data with hidden axes and no tooltips, and a RectangularSection marks the
range visible in the main chart. Both charts set the same left and right DrawMargin, so their plot areas line up.
The sync goes both ways:
- When the main chart updates (after a zoom or a pan), its
UpdateStartedevent copies the X axis limits to theXiandXjof the section. - While the pointer is pressed on the small chart, each move converts the pointer position to data coordinates with
ScalePixelsToData, centers the section there keeping its width, and sets the same range as theMinLimitandMaxLimitof the main chart's X axis.

@page "/General/Scrollable"
@using LiveChartsCore.Kernel.Sketches;
@using LiveChartsCore.Measure
@using LiveChartsCore.SkiaSharpView.Blazor;
@using LiveChartsCore.SkiaSharpView.Drawing;
@using LiveChartsCore;
@using LiveChartsCore.Defaults;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Painting;
@using SkiaSharp;
@using System.Collections.ObjectModel
<div style="max-width: 800px">
<CartesianChart @ref="_mainChart"
Series="@mainSeries"
XAxes="@mainAxes"
ZoomMode="LiveChartsCore.Measure.ZoomAndPanMode.X"
DrawMargin="@drawMargin">
</CartesianChart>
</div>
<div style="height: 100px; max-width:500px;">
<CartesianChart
@ref="_scrollableChart"
Series="@scrollbarSeries"
DrawMargin="@drawMargin"
Sections="@thumbs"
XAxes="@invisibleX"
YAxes="@invisibleY"
OnPointerDownCallback="OnPointerDown"
OnPointerUpCallback="OnPointerUp"
OnPointerMoveCallback="OnPointerMove"
TooltipPosition="LiveChartsCore.Measure.TooltipPosition.Hidden">
</CartesianChart>
</div>
@code {
private bool _isDown;
public CartesianChart _mainChart = null!;
public CartesianChart _scrollableChart = null!;
private ObservableCollection<ObservablePoint> _values = new();
private Axis[] mainAxes;
private ISeries[] mainSeries;
private ISeries[] scrollbarSeries;
private Margin drawMargin = new(100, Margin.Auto, 50, Margin.Auto);
private RectangularSection[] thumbs;
private Axis[] invisibleX = new[] { new Axis { IsVisible = false } };
private Axis[] invisibleY = new[] { new Axis { IsVisible = false } };
protected override void OnInitialized()
{
var trend = 1000;
var r = new Random();
for (var i = 0; i < 500; i++)
_values.Add(new ObservablePoint(i, trend += r.Next(-20, 20)));
mainSeries = new ISeries[]
{
new LineSeries<ObservablePoint>
{
Values = _values,
GeometryStroke = null,
GeometryFill = null,
DataPadding = new(0, 1)
}
};
mainAxes = new[] { new Axis() };
scrollbarSeries = new ISeries[]
{
new LineSeries<ObservablePoint>
{
Values = _values,
GeometryStroke = null,
GeometryFill = null,
DataPadding = new(0, 1)
}
};
thumbs = new[]
{
new RectangularSection
{
Fill = new SolidColorPaint(new SKColor(255, 205, 210, 100))
}
};
}
protected override void OnAfterRender(bool firstRender)
{
base.OnAfterRender(firstRender);
_mainChart.UpdateStarted += OnChart_Updated;
}
private void OnChart_Updated(IChartView chart)
{
var x = _mainChart.XAxes.First();
var thumb = thumbs[0];
thumb.Xi = x.MinLimit;
thumb.Xj = x.MaxLimit;
}
private void OnPointerDown(PointerEventArgs e) => _isDown = true;
private void OnPointerUp(PointerEventArgs e) => _isDown = false;
private void OnPointerMove(PointerEventArgs e)
{
if (!_isDown) return;
var positionInData = _scrollableChart.ScalePixelsToData(new(e.OffsetX, e.OffsetY));
var thumb = thumbs[0];
var currentRange = thumb.Xj - thumb.Xi;
thumb.Xi = positionInData.X - currentRange / 2;
thumb.Xj = positionInData.X + currentRange / 2;
mainAxes[0].MinLimit = thumb.Xi;
mainAxes[0].MaxLimit = thumb.Xj;
}
}
Zoom and pan from code
The chart engine has the methods that the gestures call. They take the flags to apply, so they work even when
ZoomMode is None, for example to zoom with buttons or with your own gestures. Positions and distances are in pixels.
// where myChart is a reference to the chart in the UI
var engine = (CartesianChartEngine)myChart.CoreChart;
// zooms in on the X axis, keeping the value at the pixel (100, 100) in place
engine.Zoom(ZoomAndPanMode.X, new(100, 100), ZoomDirection.ZoomIn);
// pans both axes by 10 pixels
engine.Pan(ZoomAndPanMode.Both, new(10, 10));
// zoom by section: starts the rectangle at (100, 100),
engine.StartZoomingSection(ZoomAndPanMode.Both, new(100, 100));
// grows the drawn rectangle to (150, 150), the zoom is not applied yet,
engine.GrowZoomingSection(ZoomAndPanMode.Both, new(150, 150));
// and zooms to the rectangle that ends at (200, 200)
engine.EndZoomingSection(ZoomAndPanMode.Both, new(200, 200));
Zoom honours the NoFit flag it receives: without it, the zoom is fitted to the data, as the wheel does.